package Test;

import sun.util.resources.ca.CalendarData_ca;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class MyDate {
    private GregorianCalendar date;

    public MyDate(){
        date=new GregorianCalendar();
    }

    public static void main(String[] args) {
        MyDate myDate=new MyDate();
        Scanner sc=new Scanner(System.in);
        System.out.println("现在的日期："+myDate);

        System.out.println("请输入你要设置的日期： 年 月 日");

        int year=sc.nextInt();
        int month=sc.nextInt();
        int day=sc.nextInt();
        myDate.setDate(year,month,day);
        System.out.println("设置成功："+myDate.toString());

        System.out.println("请输入要增加的field和value：(YEAR=1,MONTH=2,DAY=5)");
        int field=sc.nextInt();
        int value=sc.nextInt();

        myDate.addDate(field,value);
        System.out.println("修改后的日期为: "+myDate.toString());


    }

    public void setDate(int Year,int Month,int Day){
        date.set(Year,Month,Day);
    }

    public void addDate(int field,int amount){
        date.add(field,amount);

    }

    @Override
    public String toString() {
        return date.get(Calendar.YEAR)+"/"+date.get(Calendar.MONTH)+"/"+date.get(Calendar.DAY_OF_MONTH);
    }
}
